package com.fr.report;

import com.fr.base.FRFont;
import com.fr.base.background.Background;
import com.fr.report.core.ReportHFCore;
import com.fr.report.core.headerfooter.DateHFElement;
import com.fr.report.core.headerfooter.HFElement;
import com.fr.report.core.headerfooter.HFPaintable;
import com.fr.report.core.headerfooter.ImageHFElement;
import com.fr.report.core.headerfooter.ImageHFPaintable;
import com.fr.report.core.headerfooter.NewLineHFElement;
import com.fr.report.core.headerfooter.NumberOfPageHFElement;
import com.fr.report.core.headerfooter.PageNumberHFElement;
import com.fr.report.core.headerfooter.TextHFElement;
import com.fr.report.core.headerfooter.TextHFPaintable;
import com.fr.report.core.headerfooter.TimeHFElement;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D.Double;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;

public class ReportHF extends ReportHFCore
{
  private Background background = null;
  private boolean printBackground = true;

  public Background getBackground()
  {
    return this.background;
  }

  public void setBackground(Background paramBackground)
  {
    this.background = paramBackground;
  }

  public boolean isPrintBackground()
  {
    return this.printBackground;
  }

  public void setPrintBackground(boolean paramBoolean)
  {
    this.printBackground = paramBoolean;
  }

  public void addLeftText(String paramString, FRFont paramFRFont)
  {
    addLeftText(-1, paramString, paramFRFont);
  }

  public void addLeftText(int paramInt, String paramString, FRFont paramFRFont)
  {
    addHFElement(2, paramInt, new TextHFElement(paramString, paramFRFont));
  }

  public void addCenterText(String paramString, FRFont paramFRFont)
  {
    addCenterText(-1, paramString, paramFRFont);
  }

  public void addCenterText(int paramInt, String paramString, FRFont paramFRFont)
  {
    addHFElement(0, paramInt, new TextHFElement(paramString, paramFRFont));
  }

  public void addRightText(String paramString, FRFont paramFRFont)
  {
    addRightText(-1, paramString, paramFRFont);
  }

  public void addRightText(int paramInt, String paramString, FRFont paramFRFont)
  {
    addHFElement(4, paramInt, new TextHFElement(paramString, paramFRFont));
  }

  public void addLeftPageNumber(FRFont paramFRFont)
  {
    addLeftPageNumber(-1, paramFRFont);
  }

  public void addLeftPageNumber(int paramInt, FRFont paramFRFont)
  {
    addHFElement(2, paramInt, new PageNumberHFElement(paramFRFont));
  }

  public void addCenterPageNumber(FRFont paramFRFont)
  {
    addCenterPageNumber(-1, paramFRFont);
  }

  public void addCenterPageNumber(int paramInt, FRFont paramFRFont)
  {
    addHFElement(0, paramInt, new PageNumberHFElement(paramFRFont));
  }

  public void addRightPageNumber(FRFont paramFRFont)
  {
    addRightPageNumber(-1, paramFRFont);
  }

  public void addRightPageNumber(int paramInt, FRFont paramFRFont)
  {
    addHFElement(4, paramInt, new PageNumberHFElement(paramFRFont));
  }

  public void addLeftNumberOfPage(FRFont paramFRFont)
  {
    addLeftNumberOfPage(-1, paramFRFont);
  }

  public void addLeftNumberOfPage(int paramInt, FRFont paramFRFont)
  {
    addHFElement(2, paramInt, new NumberOfPageHFElement(paramFRFont));
  }

  public void addCenterNumberOfPage(FRFont paramFRFont)
  {
    addCenterNumberOfPage(-1, paramFRFont);
  }

  public void addCenterNumberOfPage(int paramInt, FRFont paramFRFont)
  {
    addHFElement(0, paramInt, new NumberOfPageHFElement(paramFRFont));
  }

  public void addRightNumberOfPage(FRFont paramFRFont)
  {
    addRightNumberOfPage(-1, paramFRFont);
  }

  public void addRightNumberOfPage(int paramInt, FRFont paramFRFont)
  {
    addHFElement(4, paramInt, new NumberOfPageHFElement(paramFRFont));
  }

  public void addLeftNewLine()
  {
    addLeftNewLine(-1);
  }

  public void addLeftNewLine(int paramInt)
  {
    addHFElement(2, paramInt, new NewLineHFElement());
  }

  public void addCenterNewLine()
  {
    addCenterNewLine(-1);
  }

  public void addCenterNewLine(int paramInt)
  {
    addHFElement(0, paramInt, new NewLineHFElement());
  }

  public void addRightNewLine()
  {
    addRightNewLine(-1);
  }

  public void addRightNewLine(int paramInt)
  {
    addHFElement(4, paramInt, new NewLineHFElement());
  }

  public void addLeftImage(Image paramImage)
  {
    addLeftImage(-1, paramImage);
  }

  public void addLeftImage(int paramInt, Image paramImage)
  {
    addHFElement(2, paramInt, new ImageHFElement(paramImage));
  }

  public void addCenterImage(Image paramImage)
  {
    addCenterImage(-1, paramImage);
  }

  public void addCenterImage(int paramInt, Image paramImage)
  {
    addHFElement(0, paramInt, new ImageHFElement(paramImage));
  }

  public void addRightImage(Image paramImage)
  {
    addRightImage(-1, paramImage);
  }

  public void addRightImage(int paramInt, Image paramImage)
  {
    addHFElement(4, paramInt, new ImageHFElement(paramImage));
  }

  public void addLeftDate(FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addLeftDate(-1, paramFRFont, paramDateFormat);
  }

  public void addLeftDate(int paramInt, FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addHFElement(2, paramInt, new DateHFElement(paramFRFont, paramDateFormat));
  }

  public void addCenterDate(FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addCenterDate(-1, paramFRFont, paramDateFormat);
  }

  public void addCenterDate(int paramInt, FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addHFElement(0, paramInt, new DateHFElement(paramFRFont, paramDateFormat));
  }

  public void addRightDate(FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addRightDate(-1, paramFRFont, paramDateFormat);
  }

  public void addRightDate(int paramInt, FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addHFElement(4, paramInt, new DateHFElement(paramFRFont, paramDateFormat));
  }

  public void addLeftTime(FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addLeftTime(-1, paramFRFont, paramDateFormat);
  }

  public void addLeftTime(int paramInt, FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addHFElement(2, paramInt, new TimeHFElement(paramFRFont, paramDateFormat));
  }

  public void addCenterTime(FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addCenterTime(-1, paramFRFont, paramDateFormat);
  }

  public void addCenterTime(int paramInt, FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addHFElement(0, paramInt, new TimeHFElement(paramFRFont, paramDateFormat));
  }

  public void addRightTime(FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addRightTime(-1, paramFRFont, paramDateFormat);
  }

  public void addRightTime(int paramInt, FRFont paramFRFont, DateFormat paramDateFormat)
  {
    addHFElement(4, paramInt, new TimeHFElement(paramFRFont, paramDateFormat));
  }

  private void addHFElement(int paramInt1, int paramInt2, HFElement paramHFElement)
  {
    if (paramInt1 == 4)
      if ((paramInt2 == -1) || (paramInt2 >= getRightList().size()))
        getRightList().add(paramHFElement);
      else
        getRightList().add(paramInt2, paramHFElement);
    else if (paramInt1 == 0)
      if ((paramInt2 == -1) || (paramInt2 >= getCenterList().size()))
        getCenterList().add(paramHFElement);
      else
        getCenterList().add(paramInt2, paramHFElement);
    else if ((paramInt2 == -1) || (paramInt2 >= getLeftList().size()))
      getLeftList().add(paramHFElement);
    else
      getLeftList().add(paramInt2, paramHFElement);
  }

  public void paint(Graphics2D paramGraphics2D, Rectangle2D paramRectangle2D, int paramInt1, int paramInt2, int paramInt3, int paramInt4, boolean paramBoolean)
  {
    List localList = toPaintableList(paramInt1, paramInt2, paramInt3, paramInt4);
    paramGraphics2D = (Graphics2D)paramGraphics2D.create();
    paramGraphics2D.clip(paramRectangle2D);
    paramGraphics2D.translate(paramRectangle2D.getX(), paramRectangle2D.getY());
    if ((this.background != null) && (((!(paramBoolean)) || (this.printBackground))))
      this.background.paint(paramGraphics2D, new Rectangle2D.Double(0.0D, 0.0D, paramRectangle2D.getWidth(), paramRectangle2D.getHeight()));
    for (int i = 0; i < localList.size(); ++i)
    {
      HFPaintable localHFPaintable = (HFPaintable)localList.get(i);
      localHFPaintable.paint(paramGraphics2D);
    }
    paramGraphics2D.dispose();
  }

  private List toPaintableList(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    HFElement localHFElement;
    HFPaintable localHFPaintable1;
    double d5;
    int i1;
    HFPaintable localHFPaintable5;
    ArrayList localArrayList1 = new ArrayList();
    double d1 = 0.0D;
    double d2 = 0.0D;
    ArrayList localArrayList2 = new ArrayList();
    List localList = getLeftList();
    for (int i = 0; i < localList.size(); ++i)
    {
      localHFElement = (HFElement)localList.get(i);
      localHFPaintable1 = createPaintable(localHFElement, paramInt3, paramInt4);
      localHFPaintable1.setPaintLocation(new Point2D.Double(d1, d2));
      d1 += localHFElement.getSize().getWidth();
      if (localHFElement instanceof NewLineHFElement)
      {
        d1 = 0.0D;
        if (localArrayList2.size() <= 0)
        {
          d2 += localHFElement.getSize().getHeight();
        }
        else
        {
          d5 = 0.0D;
          for (i1 = 0; i1 < localArrayList2.size(); ++i1)
          {
            localHFPaintable5 = (HFPaintable)localArrayList2.get(i1);
            d5 = Math.max(d5, localHFPaintable5.getHFElement().getSize().getHeight());
          }
          d2 += d5;
        }
        localArrayList2.clear();
      }
      else
      {
        localArrayList2.add(localHFPaintable1);
        localArrayList1.add(localHFPaintable1);
      }
    }
    d1 = 0.0D;
    d2 = 0.0D;
    localArrayList2 = new ArrayList();
    localList = getCenterList();
    for (i = 0; i < localList.size(); ++i)
    {
      localHFElement = (HFElement)localList.get(i);
      localHFPaintable1 = createPaintable(localHFElement, paramInt3, paramInt4);
      if (localHFElement instanceof NewLineHFElement)
      {
        if (localArrayList2.size() > 0)
        {
          d1 = 0.0D;
          d5 = 0.0D;
          for (i1 = 0; i1 < localArrayList2.size(); ++i1)
          {
            localHFPaintable5 = (HFPaintable)localArrayList2.get(i1);
            d5 += localHFPaintable5.getHFElement().getSize().getWidth();
          }
          d1 = (int)(paramInt1 - d5) / 2;
          for (i1 = 0; i1 < localArrayList2.size(); ++i1)
          {
            localHFPaintable5 = (HFPaintable)localArrayList2.get(i1);
            localHFPaintable5.setPaintLocation(new Point2D.Double(d1, d2));
            d1 += localHFPaintable5.getHFElement().getSize().getWidth();
          }
        }
        if (localArrayList2.size() <= 0)
        {
          d2 += localHFElement.getSize().getHeight();
        }
        else
        {
          d5 = 0.0D;
          for (i1 = 0; i1 < localArrayList2.size(); ++i1)
          {
            localHFPaintable5 = (HFPaintable)localArrayList2.get(i1);
            d5 = Math.max(d5, localHFPaintable5.getHFElement().getSize().getHeight());
          }
          d2 += d5;
        }
        localArrayList2.clear();
      }
      else
      {
        localArrayList2.add(localHFPaintable1);
        localArrayList1.add(localHFPaintable1);
      }
    }
    if (localArrayList2.size() > 0)
    {
      HFPaintable localHFPaintable3;
      d1 = 0.0D;
      double d3 = 0.0D;
      for (int k = 0; k < localArrayList2.size(); ++k)
      {
        localHFPaintable3 = (HFPaintable)localArrayList2.get(k);
        d3 += localHFPaintable3.getHFElement().getSize().getWidth();
      }
      d1 = (int)(paramInt1 - d3) / 2;
      for (k = 0; k < localArrayList2.size(); ++k)
      {
        localHFPaintable3 = (HFPaintable)localArrayList2.get(k);
        localHFPaintable3.setPaintLocation(new Point2D.Double(d1, d2));
        d1 += localHFPaintable3.getHFElement().getSize().getWidth();
      }
      localArrayList2.clear();
    }
    d2 = 0.0D;
    localList = getRightList();
    for (int j = 0; j < localList.size(); ++j)
    {
      localHFElement = (HFElement)localList.get(j);
      HFPaintable localHFPaintable2 = createPaintable(localHFElement, paramInt3, paramInt4);
      if (localHFElement instanceof NewLineHFElement)
      {
        double d6;
        if (localArrayList2.size() > 0)
        {
          d1 = 0.0D;
          d6 = 0.0D;
          for (i1 = 0; i1 < localArrayList2.size(); ++i1)
          {
            localHFPaintable5 = (HFPaintable)localArrayList2.get(i1);
            d6 += localHFPaintable5.getHFElement().getSize().getWidth();
          }
          d1 = paramInt1 - d6;
          for (i1 = 0; i1 < localArrayList2.size(); ++i1)
          {
            localHFPaintable5 = (HFPaintable)localArrayList2.get(i1);
            localHFPaintable5.setPaintLocation(new Point2D.Double(d1, d2));
            d1 += localHFPaintable5.getHFElement().getSize().getWidth();
          }
        }
        if (localArrayList2.size() <= 0)
        {
          d2 += localHFElement.getSize().getHeight();
        }
        else
        {
          d6 = 0.0D;
          for (i1 = 0; i1 < localArrayList2.size(); ++i1)
          {
            localHFPaintable5 = (HFPaintable)localArrayList2.get(i1);
            d6 = Math.max(d6, localHFPaintable5.getHFElement().getSize().getHeight());
          }
          d2 += d6;
        }
        localArrayList2.clear();
      }
      else
      {
        localArrayList2.add(localHFPaintable2);
        localArrayList1.add(localHFPaintable2);
      }
    }
    if (localArrayList2.size() > 0)
    {
      HFPaintable localHFPaintable4;
      d1 = 0.0D;
      double d4 = 0.0D;
      for (int l = 0; l < localArrayList2.size(); ++l)
      {
        localHFPaintable4 = (HFPaintable)localArrayList2.get(l);
        d4 += localHFPaintable4.getHFElement().getSize().getWidth();
      }
      d1 = paramInt1 - d4;
      for (l = 0; l < localArrayList2.size(); ++l)
      {
        localHFPaintable4 = (HFPaintable)localArrayList2.get(l);
        localHFPaintable4.setPaintLocation(new Point2D.Double(d1, d2));
        d1 += localHFPaintable4.getHFElement().getSize().getWidth();
      }
      localArrayList2.clear();
    }
    return localArrayList1;
  }

  private HFPaintable createPaintable(HFElement paramHFElement, int paramInt1, int paramInt2)
  {
    if (paramHFElement instanceof PageNumberHFElement)
      ((PageNumberHFElement)paramHFElement).setText("" + paramInt1);
    else if (paramHFElement instanceof NumberOfPageHFElement)
      ((NumberOfPageHFElement)paramHFElement).setText("" + paramInt2);
    if (paramHFElement instanceof ImageHFElement)
      return new ImageHFPaintable((ImageHFElement)paramHFElement);
    if (paramHFElement instanceof TextHFElement)
      return new TextHFPaintable((TextHFElement)paramHFElement);
    return new TextHFPaintable(new TextHFElement());
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ReportHF localReportHF = (ReportHF)super.clone();
    if (getBackground() != null)
      localReportHF.setBackground((Background)getBackground().clone());
    return localReportHF;
  }
}